//
//  HomeMenuView.m
//  ReceiptDelivery
//
//  Created by 吕晶 on 2020/7/27.
//  Copyright © 2020 吕晶. All rights reserved.
//

#import "HomeMenuView.h"

@interface HomeMenuView ()

@property (nonatomic, strong) UILabel *countLab;
@property (nonatomic, strong) UILabel *nameLab;
@property (nonatomic, strong) UIButton *clickBtn;

@end

@implementation HomeMenuView

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        self.countLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 14, frame.size.width, 36)];
        self.countLab.textAlignment = NSTextAlignmentCenter;
        self.countLab.font = BoldFontOfSize(30);
        [self addSubview:self.countLab];
        
        self.nameLab = [[UILabel alloc] initWithFrame:CGRectMake(0, self.countLab.nim_bottom + 6.5, frame.size.width, 15)];
        self.nameLab.textAlignment = NSTextAlignmentCenter;
        self.nameLab.font = [UIFont systemFontOfSize:14];
        [self addSubview:self.nameLab];
        
        self.clickBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)];
        [self.clickBtn addTarget:self action:@selector(btnClick) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:self.clickBtn];
    }
    return self;
}

- (void)btnClick {
    if (self.clickBlock) {
        self.clickBlock();
    }
}

-(void)setMenuModel:(HomeMenuModel *)menuModel {
    _menuModel = menuModel;
    if (menuModel.isMain) {
        if (menuModel.isWarning) {
            self.backgroundColor = HexColorA(0xF99090, 0.4);
            self.layer.masksToBounds = YES;
            self.layer.cornerRadius = 6;
            
            self.countLab.textColor = HexColor(0xF35959);
            self.nameLab.textColor = HexColor(0xF35959);
        }else {
            self.backgroundColor = HexColorA(0xFBA962, 0.1);
            self.layer.masksToBounds = YES;
            self.layer.cornerRadius = 6;
            
            self.countLab.textColor = HexColor(0xFBA962);
            self.nameLab.textColor = HexColorA(0x2B2C44, 0.8);
        }
    }else {
        self.backgroundColor = HexColor(0xffffff);
        self.layer.masksToBounds = YES;
        self.layer.cornerRadius = 6;
        
        self.countLab.textColor = HexColor(0xDBDCE6);
        self.nameLab.textColor = HexColor(0x2B2C44);
    }
    self.countLab.text = [NSString stringWithFormat:@"%ld",(long)menuModel.count];
    self.nameLab.text = menuModel.title;
}

@end
